package plugins;

import framework.BoardImpl;
import interfaces.Cell;
import interfaces.Command;
import interfaces.State;

/**
 * The Class ConwayCell, used for Conway's Game of Life.
 */
public class ConwayCell implements Cell {
	
	/** The state. */
	State state;

	/**
	 * Die. Makes this previously alive cell die
	 */
	public void die() {
		state = new DeadState();
	}
	
	/**
	 * Live. Makes this previously dead cell come to life
	 */
	public void live() {
		state = new AliveState();
	}

	/**
	 * get the Cell's State 
	 * @return this Cell's State - either alive or dead
	 */
	public State getState() {
		return state;
	}

	/**
	 * set the Cell's State - either alive or dead
	 * @param s State to set to this Cell
	 */
	public void setState(State s) {
		state = s;
	}

	/**
	 * Act. Tells the automaton to call its algorithm and act
	 * @param board - the board that contains the automaton
	 * @param row - cell row
	 * @param col - cell column
	 * @return command that cell needs to perform
	 */
	public Command act(BoardImpl board, int row, int col) {
		Command c = ConwayAlgorithm.getAlgorithm().act(board, this, row, col);
		return c;
	}
	
	@Override
	public ConwayCell clone(){
		ConwayCell cc = new ConwayCell();
		cc.setState(getState().clone());
		return cc;
	}
}